﻿Imports System.Threading
Imports StandAuto.Models

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles BtnVeiculos.Click
        FormVeiculos.Show()
    End Sub

    Private Sub SairToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SairToolStripMenuItem.Click
        Close()
    End Sub

    Private Sub AnimarBotao(botao As Button, texto As String)
        If botao.Text = texto Then
            botao.Text = ""
        End If
        Dim meio = texto.Length / 2
        Thread.Sleep(Math.Abs(200 * (1 / IIf(meio - botao.Text.Length = 0, 1, meio - botao.Text.Length))))
        'ToolStripStatusLabel1.Text = botao.Text.Length & " / " & meio & " / 250/1/meio-length=" & 250 * (1 / IIf(meio - botao.Text.Length = 0, 1, meio - botao.Text.Length))
        botao.Text = texto.Substring(0, botao.Text.Length + 1)
        Application.DoEvents()
        If botao.Text <> texto Then
            AnimarBotao(botao, texto)
        Else
            Timer1.Enabled = True
        End If

    End Sub
    Private Sub animabotoes()
        Dim botao As New List(Of Button)
        Dim idx As Integer
        Me.Controls.OfType(Of GroupBox).Select(Function(x) x.Controls.OfType(Of Button)()).ToList().
            ForEach(Function(z)
                        botao.AddRange(z)
                        Return True
                    End Function)

        idx = botao.Count() - 1
        'butao ao calhas
        Randomize()
        idx *= Rnd()
        If Not botao.Any() Then
            Return
        End If
        AnimarBotao(botao(idx), botao(idx).Text)
        Dim dt As DateTime = DateTime.Now
        While dt.AddSeconds(2) > DateTime.Now
            Application.DoEvents()
        End While

        animabotoes()

    End Sub


    Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
        'animabotoes()
        ToolStripTextBox1.Text = AcessoCamadaDeDados.getSetting("URLREPORT")
    End Sub


    Private Sub BtnVendedores_Click(sender As Object, e As EventArgs) Handles BtnVendedores.Click
        FormVendedores.Show()
    End Sub

    Private Sub BtnClientes_Click(sender As Object, e As EventArgs) Handles BtnClientes.Click
        FormClientes.Show()
    End Sub

    Private Sub BtnFornecedor_Click(sender As Object, e As EventArgs) Handles BtnFornecedor.Click
        FormFornecedores.Show()
    End Sub



    Private Sub DefiniçõesToolStripMenuItem_DropDownClosed(sender As Object, e As EventArgs) Handles DefiniçõesToolStripMenuItem.DropDownClosed
        If String.IsNullOrWhiteSpace(ToolStripTextBox1.Text) Then
            ToolStripTextBox1.Text = AcessoCamadaDeDados.getSetting("URLREPORT")
        Else
            AcessoCamadaDeDados.saveSetting("URLREPORT", ToolStripTextBox1.Text)
        End If
    End Sub

    Private Sub FornecedoresToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles FornecedoresToolStripMenuItem.Click
        Dim url As String = AcessoCamadaDeDados.getSetting("URLREPORT")
        System.Diagnostics.Process.Start(url & "/Objects/fornecedores")
    End Sub
    Private Sub VeiculosToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles VeiculosToolStripMenuItem1.Click
        Dim url As String = AcessoCamadaDeDados.getSetting("URLREPORT")
        System.Diagnostics.Process.Start(url & "/Objects/veiculos")
    End Sub

    Private Sub ClientesToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ClientesToolStripMenuItem.Click
        Dim url As String = AcessoCamadaDeDados.getSetting("URLREPORT")
        System.Diagnostics.Process.Start(url & "/Objects/clientes")
    End Sub

    Private Sub VendedoresToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles VendedoresToolStripMenuItem1.Click
        Dim url As String = AcessoCamadaDeDados.getSetting("URLREPORT")
        System.Diagnostics.Process.Start(url & "/Objects/vendedores")
    End Sub

    Private Sub TodasAsVendasToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles TodasAsVendasToolStripMenuItem.Click
        Dim url As String = AcessoCamadaDeDados.getSetting("URLREPORT")
        System.Diagnostics.Process.Start(url & "/transacao/vendas")
    End Sub

    Private Sub TodasAsComprasToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles TodasAsComprasToolStripMenuItem.Click
        Dim url As String = AcessoCamadaDeDados.getSetting("URLREPORT")
        System.Diagnostics.Process.Start(url & "/transacao/compras")
    End Sub

    Private Sub BtnVendas_Click(sender As Object, e As EventArgs) Handles BtnVendas.Click
        FormTransacao.Show()
    End Sub

    Private Sub TransaçõesToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles TransaçõesToolStripMenuItem.Click

    End Sub

    Private Sub CompraToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CompraToolStripMenuItem.Click
        FormTransacao.Show()
    End Sub

    Private Sub CriarToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CriarToolStripMenuItem.Click

    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        ToolStripStatusLabel1.Text = "Stand Auto - " & DateTime.Now.ToString("HH:mm:ss")
    End Sub
End Class
